import axios from 'axios';
import {getAjaxurl,delCookie} from './OperatesCookie.js';
//请求文档管理
// http://10.60.49.69:8080/swagger-ui.html#!/MenuApi/getAllMenuResultListUsingGET_1

// localStorage.setItem("myIps","http://10.60.49.66:8088");

axios.defaults.withCredentials = true;

// 指示了是否该使用类似cookies,authorization headers(头部授权)或者TLS客户端证书这一类资格证书来创建一个跨站点访问控制（cross-site Access-Control）请求
// axios.defaults.withCredentials = true;

 //axios.defaults.baseURL = getAjaxurl();


// axios.defaults.headers.common['token']=localStorage.getItem('token');
// axios.defaults.headers.common['session']=localStorage.getItem('session');

axios.interceptors.response.use((response) => {
    if (response.status === 200 || response.status === 201) {
        if (response.data.code === 801 || response.data.code === 802 || response.data.code === 400) {
            // delCookie('url');
            // delCookie('RoterUrl');
            delCookie('name');
            delCookie('password');
            // window.location.href = `http://10.61.121.28:5003/#/login`
             window.location.href = `${window.location.origin}/iCan/#/login`
            // window.location.href = `http://ipsapro.isoftstone.com/iCan_Test/#/login`
          // window.location.href = `http://10.61.121.21:5004/#/login`  //本地测试
        //    window.location.href = `http://ipsapro.isoftstone.com/iCan_Test/#/login`
        } else {
            // delCookie('name');
            // delCookie('password');
            // // window.location.href = `${getAjaxurl()}/#/login`
            // window.location.href = `http://10.61.121.28:5003/#/login`

            // router.push({path: '/MAG-ITS/PageSecondComponent', state: '' });
        }
    } else {
        delCookie('name');
        delCookie('password');
    // window.location.href = `http://10.61.121.28:5003/#/login`
        // window.location.href = `http://10.61.121.28:5003/#/login`
        // window.location.href = `http://ipsapro.isoftstone.com/iCan_Test/#/login`
         window.location.href = `${window.location.origin}/iCan/#/login`
        // window.location.href = `${getAjaxurl()}/#/login`
       // window.location.href = `http://10.61.121.21:5004/#/login`  //本地测试
        // window.location.href = `http://ipsapro.isoftstone.com/iCan_Test/#/login`
    }
    return response
})

export default axios;
